package algos;

import java.util.Arrays;
import java.util.Comparator;


public class HungarianTest {
	public static void main(String[] args) {
		float[][] a1 = new float[][]{
				{1, 4, 6, 3},
				{9, 7, 10, 9},
				{4, 5, 11, 7},
				//{8, 7, 8, 5},
		}; // 21
		float[][] a2 = new float[][]{
				{10, 1000, 20, 1000},
				{1000, 7, 1000, 20},
				{4, 14, 16, 18},
		}; // 435
		float[][] a3 = new float[][] {
				{90, 75, 75, 80},
				{35, 85, 55, 65},
				{125, 95, 90, 105},
				{45, 110, 95, 115},
		}; // 275
		float[][] a4 = new float[][] {
				{8, 7, 9, 9},
				{5, 2, 7, 8},
				{6, 1, 4, 9},
				{2, 3, 2, 6},
		}; // 17
		float[][] a5 = new float[][] {
				{1, 2, 3},
				{2, 4, 6},
				{3, 6, 9},
		}; // 10
		float[][] a = a1;
		HungarianAlgorithm HA = new HungarianAlgorithm();
		int[][] m = HA.computeAssignments(a);
		Arrays.sort(m, new Comparator<int[]>(){public int compare(int[]a,int[]b){return a[0]-b[0];}});
		float tc = 0;
		for (int i = 0; i < m.length; i++) {
			//if (m[i][0] < a.length && m[i][1] < a[0].length) tc += a[m[i][0]][m[i][1]];
			for (int j = 0; j < m[i].length; j++) {
				System.out.print((m[i][j]+1) + "\t");
			}
			System.out.println();
		}
		System.out.println(tc);
	}
}
